/**
* @Title: caseAuditList_Ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @date 2014年10月27日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('CaseAuditAddTabsCtrl', ['$scope', '$http','$state','$location','$stateParams',
                	'CaseAuditAddService','BaseURL','Modal',
                	function ($scope,$http,$state,$location,$stateParams,caseAuditAddService,baseUrl,Modal){
		
		$scope.caseAuditAddService = caseAuditAddService;
		var problemId = $scope.caseAuditAddService.auditProblemId;

		var codeType=['COMPLAIN_TYPE','SOURCE_TYPE'];
		$scope.complainModeList=[];
		$scope.sourceTypeList=[];
		$scope.targetTypeList=[{codeNo:"01",codeName:"医疗机构"},
		                       {codeNo:"02",codeName:"医护人员"},
		                       {codeNo:"03",codeName:"参保人员"}];
		
		function init(){
			caseAuditAddService.getHcpmsCodeList(codeType).success(function(response){
				angular.forEach(response.result,function(data,index){
					 if('COMPLAIN_TYPE' == data.codeType){
						    $scope.complainModeList.push(data);
						}else if('SOURCE_TYPE' == data.codeType){
							$scope.sourceTypeList.push(data);
						}
			    });
				//下拉框加载完成后再展示数据
				if($stateParams.auditProblemId && !angular.isUndefined($stateParams.auditProblemId)){
					var auditProblemId = $stateParams.auditProblemId;
					$scope.queryDetail(auditProblemId);
				}
		    });
		}

		$scope.queryDetail = function queryDetail(params){
			caseAuditAddService.queryCaseAuditDetail(params).success(function(data){
				var obj = data.result;
				$scope.auditFrom = obj;
				$scope.auditFrom.periodDate={start:obj.periodBeginDate,end:obj.periodEndDate};
			});
		}
		
		init();
		
		$scope.saveAudit = function(){
			var param = $scope.auditFrom;
			if($scope.auditFrom.periodDate){
				var _pdate = $scope.auditFrom.periodDate;
				param.periodBeginDate = _pdate.start;
				param.periodEndDate = _pdate.end;
			}
			// 医疗机构
			var rob = caseAuditAddService.saveCaseAudit(param,function(data){
				$scope.auditFrom.auditProblemId = data.auditProblemId;
				Modal.alert(data.msg);
			});
				 
		}
		
		$scope.backAudit = function(){
			$state.go("caseAudit");
		}
		
		$scope.sourceList=[{codeNo:'01',codeName:'群众投诉'},
			                 {codeNo:'02',codeName:'网上筛查'},
			                 {codeNo:'03',codeName:'智能预警'}];
		
		$scope.tabs=[{label:'医疗机构',id:0,url:'views/hcpms/audit/caseAudit_add_medical_list.html'},
		             {label:'医护人员',id:1,url:'views/hcpms/audit/caseAudit_add_staff_list.html'},
		             {label:'参保人',id:2,url:'views/hcpms/audit/caseAudit_add_insurance_list.html'}];
		
		$scope.selectedTab = $scope.tabs[0];
		$scope.currentTabIndex = 0;
		
		$scope.tabClick = function(tab) {
			$scope.selectedTab = tab;
			$scope.currentTabIndex=tab.id;
		}
		
		// end script
	}]);
})();
